The present invention relates to a process for preparing an aliphatic or semiaromatic polyamide, in which an aqueous composition of the monomers is subjected to an oligomerization at elevated temperature and elevated pressure, the reaction mixture is optionally subjected to a first expansion to reduce the water content, the (optionally expanded) reaction mixture is heated within a short time to a temperature above the melting temperature of the polyamides and the heated reaction mixture is subjected to a (further) expansion to reduce the water content and to a postpolymerization.